// 主要JavaScript功能文件

// 全局变量
var laytpl;
var form;
var data;
var user_list;
var dropdown;
var formSelects;
var $;
var g_user;
var g_msg;
var g_gifNumber = 0;
var tuan_level = 1;
var g_gifIndex;
var g_roomId;
var g_gameId;
var currentFilter = 'all';
var originalGifData = []; // 保存原始礼物数据
var giftListDYDM, giftListTTDM, giftListDY;

// 初始化函数
function initApp() {
	layui.use(function () {
		laytpl = layui.laytpl;
		var util = layui.util;
		form = layui.form;
		dropdown = layui.dropdown;
		formSelects = layui.formSelects;

		// 初始化礼物数据
		initGiftData();

		// 初始化用户数据
		initUserList();

		// 渲染模板
		renderTemplate();

		// 初始化各种功能
		initConfig();
		initGiftFilter();
		initRoomId();
		initGifNumber();
		initUserState();
		bindEvents();
	});
}

// 初始化礼物数据
function initGiftData() {
	giftListDYDM = [{ "img": "2001", "price": 1, "giftId": "n1/Dg1905sj1FyoBlQBvmbaDZFBNaKuKZH6zxHkv8Lg5x2cRfrKUTb8gzMs=", "remark": "仙女棒", "color": "#fc6471" }, { "img": "2002", "price": 10, "giftId": "28rYzVFNyXEXFC8HI+f/WG+I7a6lfl3OyZZjUS+CVuwCgYZrPrUdytGHu0c=", "remark": "能力药丸", "color": "#8297f8" }, { "img": "2003", "price": 19, "giftId": "fJs8HKQ0xlPRixn8JAUiL2gFRiLD9S6IFCFdvZODSnhyo9YN8q7xUuVVyZI=", "remark": "魔法镜", "color": "#362a5f" }, { "img": "2004", "price": 52, "giftId": "PJ0FFeaDzXUreuUBZH6Hs+b56Jh0tQjrq0bIrrlZmv13GSAL9Q1hf59fjGk=", "remark": "甜甜圈", "color": "#ff89ac" }, { "img": "2005", "price": 99, "giftId": "IkkadLfz7O/a5UR45p/OOCCG6ewAWVbsuzR/Z+v1v76CBU+mTG/wPjqdpfg=", "remark": "能量电池", "color": "#4d9dff" }, { "img": "2006", "price": 199, "giftId": "gx7pmjQfhBaDOG2XkWI2peZ66YFWkCWRjZXpTqb23O/epru+sxWyTV/3Ufs=", "remark": "爱的爆炸", "color": "#470773" }, { "img": "2007", "price": 299, "giftId": "YbLESoUj053FWVYPWUNOAtp4FYnb+/eZbyrLi7ndArVFz14rivgxf0cFrKs=", "remark": "派对话筒", "color": "#3f3061" }, { "img": "2008", "price": 520, "giftId": "pGLo7HKNk1i4djkicmJXf6iWEyd+pfPBjbsHmd3WcX0Ierm2UdnRR7UINvI=", "remark": "神秘空投", "color": "#e852a7" }, { "img": "2009", "price": 666, "giftId": "rHSYLYmWZvy2eal+foarBgE5qDJe3j2e96icNOhTSO/t2G0W8UVnXN3mltM=", "remark": "草莓甜点", "color": "#c11e1e" }, { "img": "20010", "price": 888, "giftId": "lsEGaeC++k/yZbzTU2ST64EukfpPENQmqEZxaK9v1+7etK+qnCRKOnDyjsE=", "remark": "超级空投", "color": "#63513f" }, { "img": "20011", "price": 999, "giftId": "CwaE5Zyq2ZvwgA4S9udpz1BTWMAM41FRkMN5WI5J8E7QJEUT6VFZK0USxig=", "remark": "生命药水", "color": "#9fa6ad" }, { "img": "20012", "price": 1200, "giftId": "P7zDZzpeO215SpUptB+aURb1+zC14UC9MY1+MHszKoF0p5gzYk8CNEbey60=", "remark": "超能喷射", "color": "#ff6cd7" }, { "img": "20013", "price": 1888, "giftId": "uieumAbz8iG6tw+fO35pOjrSoV3LuTfTCotwweg6vmNHQWhbUOn9hjwxJDQ=", "remark": "派对礼服", "color": "#d03a83" }, { "img": "20014", "price": 3000, "giftId": "rROiXLcY2saGvxHt3fAkYbWvbbikhEzbo0wpI794zEv+A2SCLrkNKYZEVuE=", "remark": "稀有宝箱", "color": "#5e298f" }];

	giftListTTDM = [{ "giftId": "1330", "remark": "666", "color": "#000000", "img": "666", "price": "0" }, { "giftId": "1289", "remark": "欢呼", "color": "#000001", "img": "TT欢呼", "price": "1" }, { "giftId": "1417", "remark": "冲呀", "color": "#000002", "img": "TT冲呀", "price": "10" }, { "giftId": "1418", "remark": "贴贴", "color": "#000003", "img": "TT贴贴", "price": "19" }, { "giftId": "1288", "remark": "COOL", "color": "#000004", "img": "TTCOOL", "price": "52" }, { "giftId": "1287", "remark": "YYDS", "color": "#000005", "img": "TTYYDS", "price": "99" }, { "giftId": "1286", "remark": "太酷啦", "color": "#000006", "img": "TT太酷啦", "price": "199" }, { "giftId": "1285", "remark": "T娘啦啦队", "color": "#000007", "img": "TTT娘啦啦队", "price": "520" }, { "giftId": "1984", "remark": "能量药水", "color": "#000008", "img": "TT能量药水", "price": "660" }, { "giftId": "1983", "remark": "T娘助威", "color": "#000009", "img": "TTT娘助威", "price": "900" }, { "giftId": "1284", "remark": "爱心冲击波", "color": "#000010", "img": "TT爱心冲击波", "price": "1200" }, { "giftId": "2227", "remark": "666（测试）", "color": "#000000", "img": "666", "price": "0" }, { "giftId": "2233", "remark": "欢呼（测试）", "color": "#000001", "img": "TT欢呼", "price": "1" }, { "giftId": "2570", "remark": "冲呀（测试）", "color": "#000002", "img": "TT冲呀", "price": "10" }, { "giftId": "2569", "remark": "贴贴（测试）", "color": "#000003", "img": "TT贴贴", "price": "19" }, { "giftId": "2569", "remark": "COOL（测试）", "color": "#000004", "img": "TTCOOL", "price": "52" }, { "giftId": "2231", "remark": "YYDS（测试）", "color": "#000005", "img": "TTYYDS", "price": "99" }, { "giftId": "2230", "remark": "太酷啦（测试）", "color": "#000006", "img": "TT太酷啦", "price": "199" }, { "giftId": "2229", "remark": "T娘啦啦队（测试）", "color": "#000007", "img": "TTT娘啦啦队", "price": "520" }, { "giftId": "2688", "remark": "能量药水（测试）", "color": "#000008", "img": "TT能量药水", "price": "660" }, { "giftId": "2689", "remark": "T娘助威（测试）", "color": "#000009", "img": "TTT娘助威", "price": "900" }, { "giftId": "2228", "remark": "爱心冲击波（测试）", "color": "#000010", "img": "TT爱心冲击波", "price": "1200" }];

	giftListDY = [{ "img": "Thuglife", "price": 99, "giftId": "Thuglife", "remark": "Thuglife", "color": "#5e298f" }, { "img": "一直陪伴你", "price": 520, "giftId": "一直陪伴你", "remark": "一直陪伴你", "color": "#5e298f" }, { "img": "一见钟情", "price": 1999, "giftId": "一见钟情", "remark": "一见钟情", "color": "#5e298f" }, { "img": "为你闪耀", "price": 9, "giftId": "为你闪耀", "remark": "为你闪耀", "color": "#5e298f" }, { "img": "云上巡礼", "price": 3999, "giftId": "云上巡礼", "remark": "云上巡礼", "color": "#5e298f" }, { "img": "亲吻", "price": 99, "giftId": "亲吻", "remark": "亲吻", "color": "#5e298f" }, { "img": "人气票", "price": 1, "giftId": "人气票", "remark": "人气票", "color": "#5e298f" }, { "img": "你最好看", "price": 2, "giftId": "你最好看", "remark": "你最好看", "color": "#5e298f" }, { "img": "你最棒棒", "price": 99, "giftId": "你最棒棒", "remark": "你最棒棒", "color": "#5e298f" }, { "img": "冰冻玫瑰", "price": 599, "giftId": "冰冻玫瑰", "remark": "冰冻玫瑰", "color": "#5e298f" }, { "img": "冰晶天鹅", "price": 999, "giftId": "冰晶天鹅", "remark": "冰晶天鹅", "color": "#5e298f" }, { "img": "冰镇西瓜", "price": 99, "giftId": "冰镇西瓜", "remark": "冰镇西瓜", "color": "#5e298f" }, { "img": "加油鸭", "price": 15, "giftId": "加油鸭", "remark": "加油鸭", "color": "#5e298f" }, { "img": "动次打次", "price": 2999, "giftId": "动次打次", "remark": "动次打次", "color": "#5e298f" }, { "img": "千年等一回", "price": 30000, "giftId": "千年等一回", "remark": "千年等一回", "color": "#5e298f" }, { "img": "喜结良缘", "price": 4500, "giftId": "喜结良缘", "remark": "喜结良缘", "color": "#5e298f" }, { "img": "夏威夷花环", "price": 99, "giftId": "夏威夷花环", "remark": "夏威夷花环", "color": "#5e298f" }, { "img": "夏日冰淇淋", "price": 99, "giftId": "夏日冰淇淋", "remark": "夏日冰淇淋", "color": "#5e298f" }, { "img": "多喝热水", "price": 126, "giftId": "多喝热水", "remark": "多喝热水", "color": "#5e298f" }, { "img": "大啤酒", "price": 2, "giftId": "大啤酒", "remark": "大啤酒", "color": "#5e298f" }, { "img": "大声说爱", "price": 199, "giftId": "大声说爱", "remark": "大声说爱", "color": "#5e298f" }, { "img": "天鹅湖", "price": 999, "giftId": "天鹅湖", "remark": "天鹅湖", "color": "#5e298f" }, { "img": "宇宙之心", "price": 18888, "giftId": "宇宙之心", "remark": "宇宙之心", "color": "#5e298f" }, { "img": "小心心", "price": 1, "giftId": "小心心", "remark": "小心心", "color": "#5e298f" }, { "img": "情意油纸伞", "price": 299, "giftId": "情意油纸伞", "remark": "情意油纸伞", "color": "#5e298f" }, { "img": "戏影浮光", "price": 8999, "giftId": "戏影浮光", "remark": "戏影浮光", "color": "#5e298f" }, { "img": "抖音", "price": 1, "giftId": "抖音", "remark": "抖音", "color": "#5e298f" }, { "img": "指尖乾坤", "price": 30000, "giftId": "指尖乾坤", "remark": "指尖乾坤", "color": "#5e298f" }, { "img": "指尖玲珑", "price": 699, "giftId": "指尖玲珑", "remark": "指尖玲珑", "color": "#5e298f" }, { "img": "捏捏小脸", "price": 99, "giftId": "捏捏小脸", "remark": "捏捏小脸", "color": "#5e298f" }, { "img": "斗战昆仑", "price": 8299, "giftId": "斗战昆仑", "remark": "斗战昆仑", "color": "#5e298f" }, { "img": "断桥相遇", "price": 6999, "giftId": "断桥相遇", "remark": "断桥相遇", "color": "#5e298f" }, { "img": "星光闪耀", "price": 9, "giftId": "星光闪耀", "remark": "星光闪耀", "color": "#5e298f" }, { "img": "星夜华服", "price": 999, "giftId": "星夜华服", "remark": "星夜华服", "color": "#5e298f" }, { "img": "星愿玫瑰", "price": 199, "giftId": "星愿玫瑰", "remark": "星愿玫瑰", "color": "#5e298f" }, { "img": "星星魔法棒", "price": 99, "giftId": "星星魔法棒", "remark": "星星魔法棒", "color": "#5e298f" }, { "img": "景泰天工", "price": 20000, "giftId": "景泰天工", "remark": "景泰天工", "color": "#5e298f" }, { "img": "晶花梦蝶", "price": 1999, "giftId": "晶花梦蝶", "remark": "晶花梦蝶", "color": "#5e298f" }, { "img": "棒棒糖", "price": 9, "giftId": "棒棒糖", "remark": "棒棒糖", "color": "#5e298f" }, { "img": "欢乐源泉", "price": 999, "giftId": "欢乐源泉", "remark": "欢乐源泉", "color": "#5e298f" }, { "img": "此生守护", "price": 8299, "giftId": "此生守护", "remark": "此生守护", "color": "#5e298f" }, { "img": "毡花物语", "price": 299, "giftId": "毡花物语", "remark": "毡花物语", "color": "#5e298f" }, { "img": "水漫金山", "price": 20000, "giftId": "水漫金山", "remark": "水漫金山", "color": "#5e298f" }, { "img": "游戏手柄", "price": 99, "giftId": "游戏手柄", "remark": "游戏手柄", "color": "#5e298f" }, { "img": "湖畔心动", "price": 4500, "giftId": "湖畔心动", "remark": "湖畔心动", "color": "#5e298f" }, { "img": "火树银花", "price": 4999, "giftId": "火树银花", "remark": "火树银花", "color": "#5e298f" }, { "img": "火烧玫瑰", "price": 520, "giftId": "火烧玫瑰", "remark": "火烧玫瑰", "color": "#5e298f" }, { "img": "爱你哟", "price": 52, "giftId": "爱你哟", "remark": "爱你哟", "color": "#5e298f" }, { "img": "爱的纸鹤", "price": 99, "giftId": "爱的纸鹤", "remark": "爱的纸鹤", "color": "#5e298f" }, { "img": "狮醒东方", "price": 10001, "giftId": "狮醒东方", "remark": "狮醒东方", "color": "#5e298f" }, { "img": "玫瑰", "price": 1, "giftId": "玫瑰", "remark": "玫瑰", "color": "#5e298f" }, { "img": "甜蜜蜜", "price": 888, "giftId": "甜蜜蜜", "remark": "甜蜜蜜", "color": "#5e298f" }, { "img": "皮影山河", "price": 1299, "giftId": "皮影山河", "remark": "皮影山河", "color": "#5e298f" }, { "img": "礼花筒", "price": 199, "giftId": "礼花筒", "remark": "礼花筒", "color": "#5e298f" }, { "img": "筝筝日上", "price": 899, "giftId": "筝筝日上", "remark": "筝筝日上", "color": "#5e298f" }, { "img": "簪花之礼", "price": 1999, "giftId": "簪花之礼", "remark": "簪花之礼", "color": "#5e298f" }, { "img": "粉丝团灯牌", "price": 1, "giftId": "粉丝团灯牌", "remark": "粉丝团灯牌", "color": "#5e298f" }, { "img": "红色高跟", "price": 999, "giftId": "红色高跟", "remark": "红色高跟", "color": "#5e298f" }, { "img": "结缘", "price": 1, "giftId": "结缘", "remark": "结缘", "color": "#5e298f" }, { "img": "绢上生花", "price": 199, "giftId": "绢上生花", "remark": "绢上生花", "color": "#5e298f" }, { "img": "绣叠成双", "price": 599, "giftId": "绣叠成双", "remark": "绣叠成双", "color": "#5e298f" }, { "img": "绮绣国色", "price": 599, "giftId": "绮绣国色", "remark": "绮绣国色", "color": "#5e298f" }, { "img": "缘启玉笛", "price": 99, "giftId": "缘启玉笛", "remark": "缘启玉笛", "color": "#5e298f" }, { "img": "缘启珠钗", "price": 99, "giftId": "缘启珠钗", "remark": "缘启珠钗", "color": "#5e298f" }, { "img": "翠屏逐风", "price": 99, "giftId": "翠屏逐风", "remark": "翠屏逐风", "color": "#5e298f" }, { "img": "花开饮春", "price": 99, "giftId": "花开饮春", "remark": "花开饮春", "color": "#5e298f" }, { "img": "花火玫瑰", "price": 999, "giftId": "花火玫瑰", "remark": "花火玫瑰", "color": "#5e298f" }, { "img": "草莓恋玫瑰", "price": 99, "giftId": "草莓恋玫瑰", "remark": "草莓恋玫瑰", "color": "#5e298f" }, { "img": "荣誉之匙", "price": 388, "giftId": "荣誉之匙", "remark": "荣誉之匙", "color": "#5e298f" }, { "img": "荣誉流星", "price": 7999, "giftId": "荣誉流星", "remark": "荣誉流星", "color": "#5e298f" }, { "img": "荧光棒", "price": 99, "giftId": "荧光棒", "remark": "荧光棒", "color": "#5e298f" }, { "img": "送你花花", "price": 49, "giftId": "送你花花", "remark": "送你花花", "color": "#5e298f" }, { "img": "造梦工厂", "price": 12688, "giftId": "造梦工厂", "remark": "造梦工厂", "color": "#5e298f" }, { "img": "重换光彩", "price": 999, "giftId": "重换光彩", "remark": "重换光彩", "color": "#5e298f" }, { "img": "钟韵情长", "price": 3499, "giftId": "钟韵情长", "remark": "钟韵情长", "color": "#5e298f" }, { "img": "闪耀星辰", "price": 99, "giftId": "闪耀星辰", "remark": "闪耀星辰", "color": "#5e298f" }, { "img": "霓虹机车", "price": 999, "giftId": "霓虹机车", "remark": "霓虹机车", "color": "#5e298f" }, { "img": "顶峰相见", "price": 999, "giftId": "顶峰相见", "remark": "顶峰相见", "color": "#5e298f" }, { "img": "鲜花", "price": 10, "giftId": "鲜花", "remark": "鲜花", "color": "#5e298f" }, { "img": "黄桃罐头", "price": 99, "giftId": "黄桃罐头", "remark": "黄桃罐头", "color": "#5e298f" }, { "img": "鼓起狮舞", "price": 899, "giftId": "鼓起狮舞", "remark": "鼓起狮舞", "color": "#5e298f" }, { "img": "鼻尖冰淇淋", "price": 99, "giftId": "鼻尖冰淇淋", "remark": "鼻尖冰淇淋", "color": "#5e298f" }, { "img": "龙头风筝", "price": 1999, "giftId": "龙头风筝", "remark": "龙头风筝", "color": "#5e298f" }, { "img": "龙抬头", "price": 99, "giftId": "龙抬头", "remark": "龙抬头", "color": "#5e298f" }];

	giftListDY.sort(function (a, b) {
		return a["price"] - b["price"];
	});
}

//初始化用户列表
function initUserList() {
	user_list = [{ "uid": "10001", "name": "清水煮岁月", "head": "1.png" }, { "uid": "10002", "name": "神爱世人", "head": "2.png" }, { "uid": "10003", "name": "旧楼天台", "head": "3.png" }, { "uid": "10004", "name": "川长思鸟来", "head": "4.png" }, { "uid": "10005", "name": "时笙", "head": "5.png" }, { "uid": "10006", "name": "搅散一池星光", "head": "6.png" }, { "uid": "10007", "name": "雪姬", "head": "7.png" }, { "uid": "10008", "name": "夕颜", "head": "8.png" }, { "uid": "10009", "name": "内心独白", "head": "9.png" }, { "uid": "10010", "name": "木浔与森", "head": "10.png" }, { "uid": "10011", "name": "沉睡在你心底", "head": "11.png" }, { "uid": "10012", "name": "软气猫", "head": "12.png" }, { "uid": "10013", "name": "沉没落日", "head": "13.png" }, { "uid": "10014", "name": "笙清初扇离", "head": "14.png" }, { "uid": "10015", "name": "像雾若雨又如风", "head": "15.png" }, { "uid": "10016", "name": "阳光的耀眼", "head": "16.png" }, { "uid": "10017", "name": "猫性小仙女", "head": "17.png" }, { "uid": "10018", "name": "巡音流歌", "head": "18.png" }, { "uid": "10019", "name": "有你在的温暖", "head": "19.png" }, { "uid": "10020", "name": "第七种人", "head": "20.png" }, { "uid": "10021", "name": "趁还年轻", "head": "21.png" }, { "uid": "10022", "name": "西施小姐", "head": "22.png" }, { "uid": "10023", "name": "于你悸动", "head": "23.png" }, { "uid": "10024", "name": "半世晨光", "head": "24.png" }, { "uid": "10025", "name": "白鹿饮清溪", "head": "25.png" }, { "uid": "10026", "name": "不觉晴光老", "head": "26.png" }, { "uid": "10027", "name": "浅唱蝶舞", "head": "27.png" }, { "uid": "10028", "name": "海棠花开", "head": "28.png" }, { "uid": "10029", "name": "初恋栀子花", "head": "29.png" }, { "uid": "10030", "name": "仙气中的可爱", "head": "30.png" }, { "uid": "10031", "name": "甜味拾荒者", "head": "31.png" }, { "uid": "10032", "name": "飞花似梦", "head": "32.png" }, { "uid": "10033", "name": "一袖清风", "head": "33.png" }, { "uid": "10034", "name": "小子,你的高傲呢", "head": "34.png" }, { "uid": "10035", "name": "谱写自己的人生", "head": "35.png" }, { "uid": "10036", "name": "浅唱心依", "head": "36.png" }, { "uid": "10037", "name": "不倦", "head": "37.png" }, { "uid": "10038", "name": "种一个月亮", "head": "38.png" }, { "uid": "10039", "name": "只撩干净人", "head": "39.png" }, { "uid": "10040", "name": "染墨绘君衣", "head": "40.png" }, { "uid": "10041", "name": "岁月添我愁", "head": "41.png" }, { "uid": "10042", "name": "那抹熟悉气息", "head": "42.png" }, { "uid": "10043", "name": "绿格杉", "head": "43.png" }, { "uid": "10044", "name": "怡然似梦", "head": "44.png" }, { "uid": "10045", "name": "愿风裁尘", "head": "45.png" }, { "uid": "10046", "name": "互游云", "head": "46.png" }, { "uid": "10047", "name": "嫣然的回眸一笑。", "head": "47.png" }, { "uid": "10048", "name": "眼眸里的光", "head": "48.png" }, { "uid": "10049", "name": "孤魂伴野鬼", "head": "49.png" }, { "uid": "10050", "name": "不屑", "head": "50.png" }, { "uid": "10051", "name": "深染樱花色", "head": "51.png" }, { "uid": "10052", "name": "简若", "head": "52.png" }, { "uid": "10053", "name": "梦想如花般盛开", "head": "53.png" }, { "uid": "10054", "name": "树飘摇", "head": "54.png" }, { "uid": "10055", "name": "甜的很正常", "head": "55.png" }, { "uid": "10056", "name": "Solitude'", "head": "56.png" }, { "uid": "10057", "name": "Palpitate", "head": "57.png" }, { "uid": "10058", "name": "Crush", "head": "58.png" }, { "uid": "10059", "name": "Ethereal", "head": "59.png" }, { "uid": "10060", "name": "Petrichor", "head": "60.png" }, { "uid": "10061", "name": "Limerence", "head": "61.png" }, { "uid": "10062", "name": "Habseligkeit", "head": "62.png" }, { "uid": "10063", "name": "Lime", "head": "63.png" }, { "uid": "10064", "name": "Lime青柠", "head": "64.png" }, { "uid": "10065", "name": "Aurora", "head": "65.png" }, { "uid": "10066", "name": "Flipped", "head": "66.png" }, { "uid": "10067", "name": "Frangipane", "head": "67.png" }, { "uid": "10068", "name": "芒果不加冰", "head": "68.png" }, { "uid": "10069", "name": "怦然心动", "head": "69.png" }, { "uid": "10070", "name": "极光", "head": "70.png" }, { "uid": "10071", "name": "杏仁奶油", "head": "71.png" }, { "uid": "10072", "name": "靠天不如靠自己.", "head": "72.png" }, { "uid": "10073", "name": "命运の我手中", "head": "73.png" }, { "uid": "10074", "name": "咬一口西瓜", "head": "74.png" }, { "uid": "10075", "name": "米老鼠", "head": "75.png" }, { "uid": "10076", "name": "柯南", "head": "76.png" }, { "uid": "10077", "name": "壹杆禽兽狙", "head": "77.png" }, { "uid": "10078", "name": "屹立在这世上", "head": "78.png" }, { "uid": "10079", "name": "小酒馆", "head": "79.png" }, { "uid": "10080", "name": "掌握梦想", "head": "80.png" }, { "uid": "10081", "name": "做你的小妖精", "head": "81.png" }, { "uid": "10082", "name": "用笑宣泄悲伤", "head": "82.png" }, { "uid": "10083", "name": "一袭可爱风", "head": "83.png" }, { "uid": "10084", "name": "风追烟花雨", "head": "84.png" }, { "uid": "10085", "name": "一万个舍不得·", "head": "85.png" }, { "uid": "10086", "name": "岛是海的一块疤", "head": "86.png" }, { "uid": "10087", "name": "雪后初暖阳*", "head": "87.png" }, { "uid": "10088", "name": "雨落伊人", "head": "88.png" }, { "uid": "10089", "name": "追随向日葵", "head": "89.png" }, { "uid": "10090", "name": "悦心自足", "head": "90.png" }, { "uid": "10091", "name": "活给自己看", "head": "91.png" }, { "uid": "10092", "name": "荡于旧街", "head": "92.png" }, { "uid": "10093", "name": "妄生", "head": "93.png" }, { "uid": "10094", "name": "蜜兔", "head": "94.png" }, { "uid": "10095", "name": "寒暄ら", "head": "95.png" }, { "uid": "10096", "name": "学会坚强", "head": "96.png" }, { "uid": "10097", "name": "粉色西装", "head": "97.png" }, { "uid": "10098", "name": "白丝妖娆", "head": "98.png" }, { "uid": "10099", "name": "浅灰色、邂逅", "head": "99.png" }, { "uid": "10100", "name": "软喵酱メ", "head": "100.png" }, { "uid": "10101", "name": "用户101", "head": "101.png" }, { "uid": "10101", "name": "炫酷小王子", "head": "101.png" }, { "uid": "10102", "name": "魔力女巫", "head": "102.png" }, { "uid": "10103", "name": "狂野风暴", "head": "103.png" }, { "uid": "10104", "name": "火焰舞者", "head": "104.png" }, { "uid": "10105", "name": "闪耀之星", "head": "105.png" }, { "uid": "10106", "name": "快乐小精灵", "head": "106.png" }, { "uid": "10107", "name": "绝地求生王者", "head": "107.png" }, { "uid": "10108", "name": "龙之守护者", "head": "108.png" }, { "uid": "10109", "name": "战斗机器", "head": "109.png" }, { "uid": "10110", "name": "神秘幽灵", "head": "110.png" }, { "uid": "10111", "name": "热血拳击手", "head": "111.png" }, { "uid": "10112", "name": "神射手", "head": "112.png" }, { "uid": "10113", "name": "超能战士", "head": "113.png" }, { "uid": "10114", "name": "雷霆闪电", "head": "114.png" }, { "uid": "10115", "name": "神奇魔术师", "head": "115.png" }, { "uid": "10116", "name": "猎杀机器人", "head": "116.png" }, { "uid": "10117", "name": "狂热舞者", "head": "117.png" }, { "uid": "10118", "name": "爆炸专家", "head": "118.png" }, { "uid": "10119", "name": "神秘刺客", "head": "119.png" }, { "uid": "10120", "name": "无敌战士", "head": "120.png" }, { "uid": "10121", "name": "狂野猎人", "head": "121.png" }, { "uid": "10122", "name": "火焰剑客", "head": "122.png" }, { "uid": "10123", "name": "魔法使者", "head": "123.png" }, { "uid": "10124", "name": "忍者刺客", "head": "124.png" }, { "uid": "10125", "name": "冰雪女王", "head": "125.png" }, { "uid": "10126", "name": "霸气王者", "head": "126.png" }, { "uid": "10127", "name": "神秘幻影", "head": "127.png" }, { "uid": "10128", "name": "猛犸巨兽", "head": "128.png" }, { "uid": "10129", "name": "极速飞车手", "head": "129.png" }, { "uid": "10130", "name": "神圣武士", "head": "130.png" }, { "uid": "10131", "name": "狂暴战神", "head": "131.png" }, { "uid": "10132", "name": "烈焰狂人", "head": "132.png" }, { "uid": "10133", "name": "神奇骑士", "head": "133.png" }, { "uid": "10134", "name": "神秘幽狼", "head": "134.png" }, { "uid": "10135", "name": "暴力摔跤手", "head": "135.png" }, { "uid": "10136", "name": "神奇魔术师", "head": "136.png" }, { "uid": "10137", "name": "雷电风暴", "head": "137.png" }, { "uid": "10138", "name": "火焰舞者", "head": "138.png" }, { "uid": "10139", "name": "神秘刺客", "head": "139.png" }, { "uid": "10140", "name": "冰雪女王", "head": "140.png" }, { "uid": "10141", "name": "狂野猎人", "head": "141.png" }, { "uid": "10142", "name": "魔法使者", "head": "142.png" }, { "uid": "10143", "name": "忍者刺客", "head": "143.png" }, { "uid": "10144", "name": "神秘幻影", "head": "144.png" }, { "uid": "10145", "name": "极速飞车手", "head": "145.png" }, { "uid": "10146", "name": "神圣武士", "head": "146.png" }, { "uid": "10147", "name": "狂暴战神", "head": "147.png" }, { "uid": "10148", "name": "烈焰狂人", "head": "148.png" }, { "uid": "10149", "name": "神奇骑士", "head": "149.png" }, { "uid": "10150", "name": "神秘幽狼", "head": "150.png" }];
	for (let i = 0; i < 500; i++) {
		let user = {
			"uid": "" + (10000 + i + 151),
			"name": "Test" + (i + 151),
			"head": (i + 151) + ".png"
		}
		user_list.push(user)
	}
}

// 渲染模板函数
function renderTemplate() {
	$ = layui.$;
	data = {
		user: user_list,
		gif: []
	};

	// 处理礼物数据
	layui.each(giftListDYDM, function (index, item) {
		data.gif.push({
			type: '抖音小玩法',
			礼物名称: item.remark,
			giftName: item.remark,
			加密后礼物id: item.giftId,
			giftId: item.giftId,
			单价: item.price,
			图片: item.img + '.png'
		});
	});

	layui.each(giftListTTDM, function (index, item) {
		data.gif.push({
			type: 'TT平台',
			礼物名称: item.remark,
			giftName: item.remark,
			加密后礼物id: item.giftId,
			giftId: item.giftId,
			单价: item.price,
			图片: item.img + '.png'
		});
	});

	layui.each(giftListDY, function (index, item) {
		data.gif.push({
			type: '抖音直播',
			礼物名称: item.remark,
			giftName: item.remark,
			加密后礼物id: item.giftId,
			giftId: item.giftId,
			单价: item.price,
			图片: item.img + '.png'
		});
	});

	data.user.forEach((res, i) => {
		n = Math.floor(Math.random() * 3);
		data.user[i].sex = n;
		data.user[i].性别描述 = n => ['无', '男', '女'][n] ?? '未知';
		data.user[i].level = Math.floor(Math.random() * 70);
		data.user[i].payGrade = Math.floor(Math.random() * 70);
		data.user[i].title = data.user[i].uid + " - " + data.user[i].name + " - " + data.user[i].sex;
		data.user[i].remark = `UID（${data.user[i].uid}） 昵称（${data.user[i].name}） 性别（${data.user[i].性别描述}） 等级（${data.user[i].level}） 消费等级（${data.user[i].payGrade}）`;
		data.user[i].index = i;
		data.user[i].head = "http://www.h2t.me/cdn/huyouyun" + i + ".jpg"
		data.user[i].price = 9999999;
	})


	// 渲染用户列表
	var getTpl1 = document.getElementById('TPL1').innerHTML;
	var elemView1 = document.getElementById('TPL1');
	laytpl(getTpl1).render(data, function (html) {
		elemView1.innerHTML = html;
	});

	// 渲染礼物列表
	var getTpl = document.getElementById('TPL').innerHTML;
	var elemView = document.getElementById('TPL');
	laytpl(getTpl).render(data, function (html) {
		elemView.innerHTML = html;
	});
}

// 初始化礼物筛选功能
function initGiftFilter() {
	// 保存原始礼物数据
	originalGifData = [...data.gif];

	// 筛选按钮点击事件
	$('.gift-filter-btn').on('click', function () {
		// 移除所有按钮的active类
		$('.gift-filter-btn').removeClass('active').addClass('layui-btn-primary');
		// 给当前按钮添加active类
		$(this).addClass('active').removeClass('layui-btn-primary');

		// 获取筛选类型
		currentFilter = $(this).data('filter');

		// 执行筛选
		filterGifts(currentFilter);
	});
}

// 筛选礼物函数
function filterGifts(filterType) {
	if (filterType === 'all') {
		data.gif = [...originalGifData];
	} else {
		data.gif = originalGifData.filter(gift => gift.type === filterType);
	}

	// 重新渲染礼物列表
	var getTpl = '{{# layui.each(d.gif, function(index, item){ }}' +
		'<div class="layui-col-md3 layui-col-xs3 layui-col-sm3">' +
		'<div class="layui-card gifItem" index="{{= index}}">' +
		'<div class="layui-card-header" style="padding: 0px;">' +
		'<span class="name">{{= item.礼物名称 }}</span>' +
		'<span class="price">{{= (parseFloat(item.单价)*10).toFixed(0) || "" }}</span>' +
		'</div>' +
		'<div class="layui-card-body">' +
		'<img draggable="false" class="img" style="width:48px;height: 48px;" src="img/{{= item.图片 }}" alt="">' +
		'</div>' +
		'</div>' +
		'</div>' +
		'{{# }); }}';
	var elemView = document.getElementById('TPL');
	laytpl(getTpl).render(data, function (html) {
		elemView.innerHTML = html;
	});
}

// 初始化配置
function initConfig() {
	let code_config = localStorage.getItem('code_config');
	if (!code_config) {
		const data = {
			config0: { name: '配置1', code: '' },
			config1: { name: '配置2', code: '' },
			config2: { name: '配置3', code: '' },
			config3: { name: '配置4', code: '' },
			config4: { name: '配置5', code: '' },
		};
		localStorage.setItem('code_config', JSON.stringify(data));
	}
	let config = JSON.parse(localStorage.getItem('code_config'));
	$('input[name="radio1"]')[0].title = config.config0.name;
	$('input[name="radio1"]')[1].title = config.config1.name;
	$('input[name="radio1"]')[2].title = config.config2.name;
	$('input[name="radio1"]')[3].title = config.config3.name;
	$('input[name="radio1"]')[4].title = config.config4.name;
	$('#hooyoocode').val(config.config0.code);
	form.render('radio');
}

// 初始化房间号
function initRoomId() {
	const savedRoomId = localStorage.getItem('roomId');
	if (savedRoomId) {
		$('#roomId').val(savedRoomId);
	}
	// 监听房间号输入框变化，实时保存
	$('#roomId').on('input', function () {
		const roomId = $(this).val();
		if (roomId) {
			localStorage.setItem('roomId', roomId);
		}
	});
}

// 初始化礼物数量
function initGifNumber() {
	const savedGifNumber = localStorage.getItem('gifnumber');
	if (savedGifNumber) {
		g_gifNumber = parseInt(savedGifNumber);
		$('#gifNumber').val(savedGifNumber);
		form.render('select'); // 重新渲染select元素
	}
}

// 初始化用户状态
function initUserState() {
	const savedUser = localStorage.getItem('user');
	if (savedUser) {
		try {
			g_user = JSON.parse(savedUser);
			if (g_user && g_user.head) {
				$('#head').attr("src", g_user.head);
				$("#demo-search-more").val(g_user.title);
			}
		} catch (e) {
			console.warn('Failed to parse saved user data:', e);
			g_user = null;
		}
	}
}

// 绑定事件
function bindEvents() {
	let radio = 0;

	// 表单事件
	form.on('radio', function (data) {
		radio = data.value;
		let config = JSON.parse(localStorage.getItem('code_config'));
		let savedConfig = config[`config${data.value}`];
		if (savedConfig !== undefined) {
			$('#hooyoocode').val(savedConfig.code);
		} else {
			$('#hooyoocode').val('');
		}
	});

	// 礼物数量选择事件
	form.on('select(gifNumber)', function (data) {
		g_gifNumber = data.value;
		localStorage.setItem("gifnumber", data.value);
	});

	// 保存代码按钮
	$('#save-code').on('click', function () {
		let config = JSON.parse(localStorage.getItem('code_config'));
		let the_code = $('#hooyoocode').val();
		layer.prompt({
			title: '请输入配置名称',
			value: config[`config${radio}`].name,
			formType: 0
		}, function (value, index, elem) {
			config[`config${radio}`].name = value;
			config[`config${radio}`].code = the_code;
			let savedConfig = config;
			localStorage.setItem('code_config', JSON.stringify(savedConfig));
			$('input[name="radio1"]')[0].title = config.config0.name;
			$('input[name="radio1"]')[1].title = config.config1.name;
			$('input[name="radio1"]')[2].title = config.config2.name;
			$('input[name="radio1"]')[3].title = config.config3.name;
			$('input[name="radio1"]')[4].title = config.config4.name;
			form.render('radio');
			layer.close(index);
		});
	});

	// 用户选择事件
	$('#TPL1').on('click', '.user-item', function () {
		var index = parseInt($(this).find(".uindex").text());
		var user = data.user[index];
		g_user = user;
		$('#head').attr("src", user.head);
		$("#demo-search-more").val(user.title);
		localStorage.setItem("head", g_user.head);
		localStorage.setItem("user", g_user.title);
		localStorage.setItem("user", JSON.stringify(g_user));
		return false;
	});

	// 礼物点击事件
	$('#TPL').on('click', '.gifItem', function () {
		g_gifIndex = parseInt($(this).attr("index"));
		let resPrice = g_gifNumber * data.gif[+g_gifIndex].单价;
		if (!g_gifNumber) {
			return layMsg('请选择数量');
		}
		if (!g_user) {
			return layMsg('请先选择用户');
		}
		if (g_user.price < resPrice) {
			return layMsg('余额不足');
		}
		let p = +g_user.price - +resPrice;
		let userInfo = g_user;
		userInfo.price = p;
		data.user.forEach(item => {
			if (item.uid == userInfo.uid) item = userInfo;
		});
		localStorage.setItem('users', JSON.stringify(data.user));
		// 手动更新 DOM
		data.user.forEach((item, index) => {
			const inputElement = document.querySelector(
				`.user-item:nth-child(${index + 1}) .layui-input`);
			if (inputElement) {
				inputElement.value = item.price;
			}
		});
		gif(g_user, g_gifIndex, g_gifNumber);
	});

	// 按钮事件
	$('#sendMsg').on('click', function () {
		if (!g_user) {
			return layMsg('请先选择用户');
		}
		g_msg = $('#msg').val();
		if (!g_msg) {
			return layMsg('请输入弹幕内容');
		}
		msg(g_user, g_msg);
		return false;
	});

	$('#send_tuan_add').on('click', function () {
		if (!g_user) {
			return layMsg('请先选择用户');
		}
		g_msg = $('#msg').val();
		tuan(g_user, g_msg, 2, 1);
		return false;
	});

	$('#send_tuan_up').on('click', function () {
		if (!g_user) {
			return layMsg('请先选择用户');
		}
		g_msg = $('#msg').val();
		tuan(g_user, g_msg, 1, tuan_level);
		return false;
	});

	$('#sendLike').on('click', function () {
		if (!g_user) {
			return layMsg('请先选择用户');
		}
		like(g_user, g_gifNumber);
		return false;
	});

	$('#send_jinfang').on('click', function () {
		if (!g_user) {
			return layMsg('请先选择用户');
		}
		g_msg = $('#msg').val();
		jinfang(g_user, g_msg);
		return false;
	});

	$('#send_guanzhu').on('click', function () {
		if (!g_user) {
			return layMsg('请先选择用户');
		}
		g_msg = $('#msg').val();
		guanzhu(g_user, g_msg);
		return false;
	});

	$('#send_fenxiang').on('click', function () {
		if (!g_user) {
			return layMsg('请先选择用户');
		}
		g_msg = $('#msg').val();
		fenxiang(g_user, g_msg);
		return false;
	});

	// 运行代码按钮
	$('#run-code').on('click', function () {
		var status = $(this).text();
		var code = $("#hooyoocode").val();

		function sleep(ms) {
			tosat("延迟" + ms + "毫秒", 101, ms);
			return new Promise(resolve => setTimeout(resolve, ms));
		}

		runCode = `async function myAsyncFunction() {
			if(status!="运行"){
				layer.msg("脚本执行中，请稍后重试，（强制停止执行请刷新网页）")
				return
			}
			$("#run").text("执行中（强制停止执行请刷新网页）..")
			tosat("开始执行脚本",100,2000);
			${code}
			await sleep(500);
			$("#run").text("运行")
			tosat("脚本执行完毕",100,2000);
		}
		myAsyncFunction();`;

		eval(runCode);
		return false;
	});
}

// 工具函数
function layMsg(msg) {
	layer.msg(msg);
}

// URL变更函数
function change_url(obj) {
	window.localStorage.setItem("msg_url_666", $(obj).val().toString().trim());
	let msg_url_666_arr = window.localStorage.getItem("msg_url_666_arr");
	msg_url_666_arr = msg_url_666_arr ? JSON.parse(msg_url_666_arr) : [];
	msg_url_666_arr.push($(obj).val().toString().trim());
	let uniqueArr = [...new Set(msg_url_666_arr)];
	window.localStorage.setItem("msg_url_666_arr", JSON.stringify(uniqueArr));
}

// 页面加载完成后初始化
document.addEventListener('DOMContentLoaded', function () {
	initApp();
});